package com.ctshk.rpc.order.bus.mapper;

import java.time.LocalDate;
import java.util.Set;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectProvider;

import com.ctshk.common.service.mapper.CtsBaseMapper;
import com.ctshk.common.service.mapper.CtsSQL;
import com.ctshk.rpc.order.bus.entity.BusOrderTourist;

/**
 * <p>
 * 巴士订单旅客信息 Mapper 接口
 * </p>
 *
 * @author 彭柳霖
 * @since 2021-02-24
 */
public interface BusOrderTouristMapper extends CtsBaseMapper<BusOrderTourist> {

	/**
	 * 根据产品ID查询座位号列表
	 * @param productId
	 * @return
	 */
//	@Select("select t.seats_number from t_bus_order_tourist t join t_bus_order tbo on t.order_id = tbo.id where t.is_deleted = 0 and tbo.is_deleted = 0 and tbo.bus_id = #{productId} and effective_time = #{querDate}")
	@SelectProvider(type = BusOrderTouristMapper.class, method = "querySeatListByProductProvider")
	Set<String> querySeatListByProduct(@Param("productId") Long productId, @Param("querDate") LocalDate querDate);
	
	static String querySeatListByProductProvider(Long productId, LocalDate querDate) {
		return new CtsSQL() {{
			SELECT_DISTINCT("t.seats_number");
			FROM("t_bus_order_tourist t");
			JOIN("t_bus_order tbo ON t.order_id = tbo.id");
			WHERE("t.is_deleted = 0 AND tbo.is_deleted = 0 and tbo.bus_id = #{productId} and tbo.effective_time = #{querDate}"
					, "(tbo.payment_status != 1 or (tbo.payment_status = 1 and tbo.pay_expire_date >= now()))");
			
		}}.toString();
	}
}
